// pages/userCenter/myHouse/myHouse.js
var app = getApp();
const request = require('../../../utils/request');
Page({
  data: {
    active: 0,
    collectList: []
  },

  onLoad() {
    this.getCollect()
  },

  toDetail: function (e) {
    wx.navigateTo({
      url: '/pages/market/marketDetail/marketDetail?goods_id=' + e.currentTarget.dataset.id
    })
  },

  getCollect() {
    wx.showLoading()
    const data = {
      token: wx.getStorageSync("token")
    }
    request.get('my_shoucang', data)
      .then(res => {
        wx.hideLoading()
        const data = res.data.map(v => {
          if (!v.price) v.price = 0
          if (!v.title) v.title = '暂无'
          return v
        })
        
        this.setData({
          goodsList: data
        })
      })
      .catch(error => {
        wx.showToast({
          icon: 'none',
          title: error.msg && error.msg
        })
      })
      .finally(_ => {
        
      })
  },
  // 删除
  delete(e){
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确认删除？',
      success(res) {
        if (res.confirm) {

          wx.showLoading()
          const data = {
            token: wx.getStorageSync("token"),
            collect_id: e.currentTarget.dataset.id
          }
          request.get('collect_del', data)
            .then(res => {
              wx.hideLoading()
              wx.showToast({
                icon: 'none',
                title: "删除成功"
              })

              that.getCollect();
              
            })
            .catch(error => {
              wx.showToast({
                icon: 'none',
                title: error.msg && error.msg
              })
            })
            .finally(_ => {
              
            })
        } else if (res.cancel) {
          
        }
      }
    })
  },
 
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
})